package logic

import (
	"anjuke/anjukerpc/models"
	"context"

	"anjuke/anjukerpc/anjukerpc"
	"anjuke/anjukerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *anjukerpc.ListRequest) (*anjukerpc.ListResponse, error) {
	// todo: add your logic here and delete this line
	var house []models.House
	models.DB.Find(&house)
	var lists []*anjukerpc.Lists
	for _, hou := range house {
		list := anjukerpc.Lists{
			Id:      int64(hou.ID),
			Name:    hou.Name,
			Content: hou.Content,
			Address: hou.Address,
		}
		lists = append(lists, &list)
	}
	return &anjukerpc.ListResponse{
		List: lists,
	}, nil
}
